using System;
using System.Drawing.Imaging; 
using System.IO; 
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for imagesProcessor
/// </summary>
/// 
public class imageProcessor
{
	public imageProcessor()
	{
		//
		// TODO: Add constructor logic here
		//
	}
   
    protected ImageFormat ImgFormat(string ext)
    {
        switch (ext)
        {
            case "JPG":
                return ImageFormat.Jpeg;

            case "GIF":
                return ImageFormat.Gif;

            case "PNG":
                return ImageFormat.Png;

            case "BMP":
                return ImageFormat.Bmp;

            default:
                return ImageFormat.Jpeg;
        }
    }

    public byte[] prepare_image(HttpPostedFile uploaded_image)
    {
        int posted_file_length = uploaded_image.ContentLength;
        byte[] result_image = null; 

        result_image = new byte[posted_file_length];
                
        uploaded_image.InputStream.Read(result_image, 0, posted_file_length);

        return result_image; 
    }

    public string get_image_ext(HttpPostedFile uploaded_image)
    {
        FileInfo file_info = new FileInfo(uploaded_image.FileName);
        
        string img_ext = file_info.Extension.Substring(1).ToUpper();

        return img_ext; 
    }

    public byte[] create_thumbnail(byte[] uploaded_image)
    {
        MemoryStream img_mem_strm = new MemoryStream(uploaded_image);

        System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(img_mem_strm);

        int new_height;

        if (bitmap.Height > 60)
        {
            new_height = 60;
        }
        else
        {
            new_height = bitmap.Height;
        }

        System.Drawing.Image tmb_img = bitmap.GetThumbnailImage(90, new_height, null, new IntPtr());
        
        return ImageToBytes(tmb_img); 
    }

    public byte[] ImageToBytes(System.Drawing.Image small_image)
    {
        MemoryStream ms = new MemoryStream();

        small_image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);  
                        
        return ms.ToArray(); 
    }
        
 }

public class image_resizer
{ 
    public int old_height; 
    public int old_width; 
    
    public int new_height; 
    public int new_width; 
   
    public image_resizer()
    {
        
    }
            
}